package com.talent.service.base.wx;

import com.talent.model.wx.WxAccessTokenVo;
import com.talent.model.wx.WxOpenIdResultVo;
import com.talent.model.wx.WxPhoneResultVo;
import com.talent.model.wx.dto.WxSnTicketDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author watson
 * @Description"
 * @date: 2025/3/13 20:10
 */

@FeignClient(name = "wx-client",url = "https://api.weixin.qq.com")
public interface WxFeignClient {


    /**
     * 获取openId
     * @param appid 微信appid
     * @param secret 微信secret
     * @param jsCode 登陆code
     * @param grantType 类型 默认 authorization_code
     * @return 获取结果
     */
    @GetMapping("/sns/jscode2session")
    WxOpenIdResultVo getOpenId(
            @RequestParam("appid") String appid,
            @RequestParam("secret") String secret,
            @RequestParam("js_code") String jsCode,
            @RequestParam(value = "grant_type",defaultValue = "authorization_code") String grantType
    );

    /**
     * 获取accessToken
     * @param appid 微信appid
     * @param secret 微信secret
     * @param grantType 类型 默认 client_credential
     * @return 获取结果
     */
    @GetMapping("/cgi-bin/token")
    WxAccessTokenVo getAccessToken(
            @RequestParam("appid") String appid,
            @RequestParam("secret") String secret,
            @RequestParam(value = "grant_type",defaultValue = "client_credential") String grantType
    );


    /**
     * 获取手机号
     * @param accessToken accessToken
     * @param openId openId
     * @param phoneCode phoneCode
     * @return 获取结果
     */
    @GetMapping("/wxa/business/getuserphonenumber")
    WxPhoneResultVo getUserPhone(
            @RequestParam(value = "access_token") String accessToken,
            @RequestParam("openid") String openId,
            @RequestParam("code") String phoneCode
    );


    /**
     * 设备获取票据
     * @param accessToken
     * @param wxSnTicketDto
     * @return
     */
    @PostMapping("/wxa/getsnticket")
    String getSnTicket(@RequestParam (value = "access_token")String accessToken,
                       @RequestBody WxSnTicketDto wxSnTicketDto);


    /**
     * 发送设备订阅消息
     * @return
     */
    @PostMapping("/cgi-bin/message/device/subscribe/send")
    String setDeviceTemplate();

}
